home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14301 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How do I change the middle of a file?
  5. Date: Fri, 29 Mar 1996 13:59:59 -0500
  6. Organization: Datalytics, Inc
  7. Message-ID: <315C332F.2648@datalytics.com>
  8. References: <4jeclc$4ob@felix.cc.gatech.edu>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Matthew W. Culbreth wrote:
  16. > Howdy,
  17. > I've got a big text file that acts as a database.  I need to be able
  18. > to search through the file, find a particular line, and change it.
  19. > I've tried opening the file in (ios::in|ios::app), but now the program
  20. > won't getline().
  21. > Any ideas?
  22. > Thanks,
  23.  
  24. You'll have to read it, line by line, searching for the line of 
  25. interest.  For each line that isn't what you want, copy it to a 
  26. new file.  When you find the one you want, write the changed 
  27. version to the new file instead.  Finally, copy the rest of the 
  28. lines to the new file.  Close both files, delete the original 
  29. file, and rename the new file to the name of the original file.
  30.  
  31. You should open the original file with an ifstream (the default 
  32. mode should be fine).  Open the new file with an ofstream (the 
  33. default mode should be fine).
  34.  
  35. -- 
  36. Robert Stewart        | My opinions are usually my own.
  37. Datalytics, Inc.    | stew@datalytics.com
  38.